package com.dynamixsoftware.printershare;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.database.DataSetObserver;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.SpannableStringBuilder;
import android.text.style.CharacterStyle;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.util.DisplayMetrics;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.dynamixsoftware.printershare.gmail.GmsProtos;
import com.dynamixsoftware.printershare.gmail.ProtoBuf;
import com.google.android.collect.Maps;
import com.google.android.googleapps.GoogleLoginCredentialsResult;
import com.google.android.googleapps.IGoogleLoginService;
import com.google.android.googleapps.IGoogleLoginService.Stub;
import com.google.android.googlelogin.GoogleLoginServiceConstants;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Vector;

public class ActivityGmail
  extends ActivityRoot
{
  public static final SimpleDateFormat df1;
  public static final SimpleDateFormat df2;
  public static final SimpleDateFormat df3;
  private static int requesting_credentials;
  private static final Map<Integer, Integer> sPriorityToLength;
  private MyAdapter adapter;
  private String[] al;
  private Object[] al_objs;
  private long client_id;
  private volatile Hashtable<String, String> cn_labels;
  private String[] credentials;
  private volatile Vector<ProtoBuf> data;
  private boolean ftoken;
  private Handler handler;
  private volatile Hashtable<Long, String> id_labels;
  private volatile String label;
  private volatile Vector<String> labels;
  private ListView mList;
  private TextView mLoading;
  private volatile Thread wt;
  
  static
  {
    if (!ActivityGmail.class.desiredAssertionStatus()) {}
    for (boolean bool = true;; bool = false)
    {
      $assertionsDisabled = bool;
      df1 = new SimpleDateFormat("h:mm a", new DateFormatSymbols(Locale.US));
      df2 = new SimpleDateFormat("MMM d", new DateFormatSymbols(Locale.US));
      df3 = new SimpleDateFormat("M/d/yyyy", new DateFormatSymbols(Locale.US));
      sPriorityToLength = Maps.newHashMap();
      return;
    }
  }
  
  private void authorize(String paramString)
  {
    this.last_error = null;
    this.credentials = new String[2];
    this.credentials[0] = paramString;
    Object localObject1;
    if (App.has_feature_gls)
    {
      localObject1 = getSystemService("account");
      if (localObject1 == null) {}
    }
    for (;;)
    {
      int n;
      int k;
      try
      {
        Object[] arrayOfObject1 = this.al_objs;
        int j = 0;
        if (arrayOfObject1 != null)
        {
          n = 0;
          int i1 = this.al.length;
          j = 0;
          if (n < i1)
          {
            if (!this.al[n].equals(paramString)) {
              break label745;
            }
            j = n;
          }
        }
        Method[] arrayOfMethod = localObject1.getClass().getMethods();
        k = 0;
        int m = arrayOfMethod.length;
        Method localMethod = null;
        if (k < m)
        {
          if ((!"getAuthToken".equals(arrayOfMethod[k].getName())) || (arrayOfMethod[k].getParameterTypes().length != 5)) {
            break label751;
          }
          localMethod = arrayOfMethod[k];
        }
        Object[] arrayOfObject2 = new Object[5];
        arrayOfObject2[0] = this.al_objs[j];
        arrayOfObject2[1] = "mail";
        arrayOfObject2[2] = Boolean.valueOf(false);
        arrayOfObject2[3] = null;
        arrayOfObject2[4] = this.handler;
        Object localObject2 = localMethod.invoke(localObject1, arrayOfObject2);
        Bundle localBundle = (Bundle)localObject2.getClass().getMethod("getResult", new Class[0]).invoke(localObject2, new Object[0]);
        Intent localIntent2 = (Intent)localBundle.getParcelable("intent");
        if (localIntent2 != null)
        {
          if (requesting_credentials == 0)
          {
            requesting_credentials = 1;
            startActivity(localIntent2);
            this.wt = null;
          }
        }
        else {
          this.credentials[1] = localBundle.getString("authtoken");
        }
      }
      catch (Exception localException3)
      {
        localException3.printStackTrace();
        App.reportThrowable(localException3);
        continue;
      }
      requesting_credentials = 0;
      authorize_done();
      return;
      Intent localIntent1 = GoogleLoginServiceConstants.SERVICE_INTENT;
      ServiceConnection local6 = new ServiceConnection()
      {
        public void onServiceConnected(ComponentName paramAnonymousComponentName, IBinder paramAnonymousIBinder)
        {
          IGoogleLoginService localIGoogleLoginService = IGoogleLoginService.Stub.asInterface(paramAnonymousIBinder);
          try
          {
            ActivityGmail.this.credentials[1] = localIGoogleLoginService.peekCredentials(ActivityGmail.this.credentials[0], "mail");
            if (ActivityGmail.this.credentials[1] == null)
            {
              GoogleLoginCredentialsResult localGoogleLoginCredentialsResult = localIGoogleLoginService.blockingGetCredentials(ActivityGmail.this.credentials[0], "mail", false);
              ActivityGmail.this.credentials[1] = localGoogleLoginCredentialsResult.getCredentialsString();
            }
            ActivityGmail.this.authorize_done();
            ActivityGmail.this.unbindService(this);
            return;
          }
          catch (Exception localException)
          {
            for (;;)
            {
              localException.printStackTrace();
              App.reportThrowable(localException);
            }
          }
        }
        
        public void onServiceDisconnected(ComponentName paramAnonymousComponentName) {}
      };
      if (!bindService(localIntent1, local6, 1))
      {
        authorize_done();
        return;
        try
        {
          if (this.credentials[0] != null)
          {
            int i = this.credentials[0].indexOf("");
            if (i > 0)
            {
              str1 = this.credentials[0].substring(i + 1);
              this.credentials[0] = this.credentials[0].substring(0, i);
              String str2 = App.glsGetAuthToken("mail", this.credentials[0], str1);
              if (str2 != null)
              {
                localEditor = this.prefs.edit();
                localEditor.putString("gmail_token_" + this.credentials[0], str2);
              }
            }
          }
        }
        catch (Exception localException1)
        {
          String str1;
          SharedPreferences.Editor localEditor;
          String str3;
          String str4;
          String str5;
          label642:
          Runnable local7;
          localException1.printStackTrace();
          App.reportThrowable(localException1);
          authorize_done();
          return;
        }
        try
        {
          str3 = App.glsGetAuthToken("cloudprint", this.credentials[0], str1);
          if (str3 != null) {
            localEditor.putString("cloud_token_" + this.credentials[0], str3);
          }
          str4 = App.glsGetAuthToken("writely", this.credentials[0], str1);
          if (str4 != null) {
            localEditor.putString("gdocs_token1_" + this.credentials[0], str4);
          }
          str5 = App.glsGetAuthToken("wise", this.credentials[0], str1);
          if (str5 != null) {
            localEditor.putString("gdocs_token2_" + this.credentials[0], str5);
          }
        }
        catch (Exception localException2)
        {
          localException2.printStackTrace();
          App.reportThrowable(localException2);
          break label642;
        }
        localEditor.commit();
        this.credentials[1] = this.prefs.getString("gmail_token_" + this.credentials[0], null);
        if (this.credentials[1] == null)
        {
          local7 = new Runnable()
          {
            public void run()
            {
              ActivityGmail.this.hideProgress();
              final View localView = LayoutInflater.from(ActivityGmail.this).inflate(2130903045, null);
              localView.findViewById(2131230742).setVisibility(0);
              EditText localEditText = (EditText)localView.findViewById(2131230739);
              localEditText.setText(ActivityGmail.this.credentials[0]);
              if (ActivityGmail.this.prefs.getString("gmail_account", null) != null)
              {
                localEditText.setInputType(0);
                localEditText.setFocusable(false);
              }
              new AlertDialog.Builder(ActivityGmail.this).setIcon(17301543).setTitle(2131099841).setView(localView).setCancelable(false).setPositiveButton(2131099703, new DialogInterface.OnClickListener()
              {
                public void onClick(DialogInterface paramAnonymous2DialogInterface, int paramAnonymous2Int)
                {
                  final String str1 = ((EditText)localView.findViewById(2131230739)).getText().toString();
                  final String str2 = ((EditText)localView.findViewById(2131230741)).getText().toString();
                  ActivityGmail.this.showProgress(ActivityGmail.this.getResources().getString(2131099746));
                  ActivityGmail.access$1002(ActivityGmail.this, new Thread()
                  {
                    public void run()
                    {
                      ActivityGmail.this.authorize(str1 + "" + str2);
                    }
                  });
                  ActivityGmail.this.wt.start();
                }
              }).setNegativeButton(2131099707, new DialogInterface.OnClickListener()
              {
                public void onClick(DialogInterface paramAnonymous2DialogInterface, int paramAnonymous2Int)
                {
                  ActivityGmail.this.authorize_done();
                }
              }).create().show();
            }
          };
          runOnUiThread(local7);
          return;
        }
      }
      return;
      label745:
      n++;
      continue;
      label751:
      k++;
    }
  }
  
  private void authorize_done()
  {
    if (this.credentials[1] != null)
    {
      int i = loadLabels();
      if (i != 0)
      {
        this.wt = null;
        if (this.prefs.getString("gmail_account", null) == null) {}
        for (int j = 1;; j++)
        {
          String str = this.prefs.getString("gls_account_" + j, null);
          if ((str == null) || (str.equals(this.credentials[0])))
          {
            SharedPreferences.Editor localEditor = this.prefs.edit();
            localEditor.putString("gls_account_" + j, this.credentials[0]);
            localEditor.putString("gmail_account", this.credentials[0]);
            localEditor.commit();
            if (i > 0) {
              runOnUiThread(new Runnable()
              {
                public void run()
                {
                  ActivityGmail.this.hideProgress();
                  ActivityGmail.this.showConversations("^i");
                }
              });
            }
            return;
          }
        }
      }
    }
    this.wt = null;
    runOnUiThread(new Runnable()
    {
      public void run()
      {
        ActivityGmail.this.hideProgress();
        if (ActivityGmail.this.prefs.getString("gmail_account", null) != null)
        {
          ActivityGmail.this.last_error = "Error: Authorization failed or network error has occured";
          ActivityGmail.this.displayLastError(new DialogInterface.OnClickListener()
          {
            public void onClick(DialogInterface paramAnonymous2DialogInterface, int paramAnonymous2Int)
            {
              ActivityGmail.this.mList.showContextMenu();
            }
          });
        }
      }
    });
  }
  
  private static void getSenderSnippet(ProtoBuf paramProtoBuf, SpannableStringBuilder paramSpannableStringBuilder, int paramInt, CharacterStyle paramCharacterStyle1, CharacterStyle paramCharacterStyle2, CharSequence paramCharSequence1, CharSequence paramCharSequence2, CharSequence paramCharSequence3, boolean paramBoolean1, boolean paramBoolean2)
  {
    assert ((!paramBoolean1) || (!paramBoolean2));
    int i;
    Map localMap;
    int j;
    Object localObject1;
    int m;
    label88:
    String str1;
    label132:
    int n;
    int i1;
    label142:
    ProtoBuf localProtoBuf2;
    Object localObject2;
    if ((paramBoolean1) || (paramBoolean2))
    {
      i = 1;
      localMap = sPriorityToLength;
      localMap.clear();
      j = -2147483648;
      localObject1 = "";
      int k = paramProtoBuf.getInt(1);
      m = paramProtoBuf.getInt(2);
      if (m > 0)
      {
        if (m != 1) {
          break label237;
        }
        localObject1 = paramCharSequence2;
      }
      if (k + m <= 1) {
        break label274;
      }
      str1 = " (" + Integer.toString(k + m) + ")";
      n = paramProtoBuf.getCount(3);
      i1 = 0;
      if (i1 >= n) {
        break label305;
      }
      localProtoBuf2 = paramProtoBuf.getProtoBuf(3, i1);
      localObject2 = localProtoBuf2.getString(4);
      if (localObject2 != null) {
        break label282;
      }
      localObject2 = "";
      label176:
      if (localProtoBuf2.getCount(3) <= 0) {
        break label299;
      }
    }
    label274:
    label282:
    label299:
    for (int i13 = localProtoBuf2.getInt(3);; i13 = 0)
    {
      localMap.put(Integer.valueOf(i13), Integer.valueOf(((CharSequence)localObject2).length()));
      j = Math.max(j, i13);
      i1++;
      break label142;
      i = 0;
      break;
      label237:
      localObject1 = paramCharSequence3 + " (" + m + ")";
      break label88;
      str1 = "";
      break label132;
      if (((CharSequence)localObject2).length() != 0) {
        break label176;
      }
      localObject2 = paramCharSequence1;
      break label176;
    }
    label305:
    int i2 = ((CharSequence)localObject1).length();
    SpannableStringBuilder localSpannableStringBuilder = null;
    if (i2 != 0)
    {
      localSpannableStringBuilder = null;
      if (0 == 0) {
        localSpannableStringBuilder = new SpannableStringBuilder();
      }
      localSpannableStringBuilder.append((CharSequence)localObject1);
      if (paramCharacterStyle2 != null) {
        localSpannableStringBuilder.setSpan(CharacterStyle.wrap(paramCharacterStyle2), 0, localSpannableStringBuilder.length(), 33);
      }
    }
    if ("".length() != 0)
    {
      if (localSpannableStringBuilder == null) {
        localSpannableStringBuilder = new SpannableStringBuilder();
      }
      if (localSpannableStringBuilder.length() != 0) {
        localSpannableStringBuilder.append(", ");
      }
      localSpannableStringBuilder.append("");
    }
    if ("".length() != 0)
    {
      if (localSpannableStringBuilder == null) {
        localSpannableStringBuilder = new SpannableStringBuilder();
      }
      if (localSpannableStringBuilder.length() != 0) {
        localSpannableStringBuilder.append(", ");
      }
      localSpannableStringBuilder.append("");
    }
    int i3 = 0;
    if (localSpannableStringBuilder != null) {
      i3 = localSpannableStringBuilder.length();
    }
    int i4;
    String str2;
    int i5;
    int i6;
    int i7;
    label547:
    int i12;
    int i10;
    label641:
    ProtoBuf localProtoBuf1;
    boolean bool2;
    label729:
    String str4;
    if ((str1.length() != 0) || (j != -2147483648))
    {
      i4 = 1;
      str2 = "";
      if ((i4 != 0) && (i3 != 0)) {
        str2 = ", ";
      }
      i5 = -1;
      i6 = i3 + (str1.length() + str2.length());
      i7 = 0;
      if (i5 < j)
      {
        if (!localMap.containsKey(Integer.valueOf(i5 + 1))) {
          break label821;
        }
        i12 = i6 + ((Integer)localMap.get(Integer.valueOf(i5 + 1))).intValue();
        if (i6 > 0) {
          i12 += 2;
        }
        if ((i12 <= paramInt) || (i7 < 2)) {
          break label814;
        }
      }
      int i8 = i6;
      int i9 = 0;
      if (i8 > paramInt) {
        i9 = (i6 - paramInt) / i7;
      }
      i10 = 0;
      if (i10 >= n) {
        break label849;
      }
      localProtoBuf1 = paramProtoBuf.getProtoBuf(3, i10);
      boolean bool1 = localProtoBuf1.getBool(1);
      String str3 = localProtoBuf1.getString(4);
      if ((str3 != null) && (str3.length() == 0)) {
        str3 = paramCharSequence1.toString();
      }
      if (i9 != 0) {
        str3 = str3.substring(0, Math.max(str3.length() - i9, 0));
      }
      if (i == 0) {
        break label827;
      }
      bool2 = paramBoolean1;
      if (localProtoBuf1.getInt(3) > i5) {
        break label846;
      }
      if (paramSpannableStringBuilder.length() != 0)
      {
        if (!bool1) {
          break label838;
        }
        str4 = " .. ";
        label757:
        paramSpannableStringBuilder.append(str4);
      }
      int i11 = paramSpannableStringBuilder.length();
      paramSpannableStringBuilder.append(str3);
      if ((bool2) && (paramCharacterStyle1 != null)) {
        paramSpannableStringBuilder.setSpan(CharacterStyle.wrap(paramCharacterStyle1), i11, paramSpannableStringBuilder.length(), 33);
      }
    }
    label814:
    label821:
    label827:
    label838:
    label846:
    for (;;)
    {
      i10++;
      break label641;
      i4 = 0;
      break;
      i6 = i12;
      i7++;
      i5++;
      break label547;
      bool2 = localProtoBuf1.getBool(2);
      break label729;
      str4 = ", ";
      break label757;
    }
    label849:
    paramSpannableStringBuilder.append(str1);
    if (i3 != 0)
    {
      paramSpannableStringBuilder.append(str2);
      paramSpannableStringBuilder.append(localSpannableStringBuilder);
    }
  }
  
  private void loadConversations(final long paramLong)
  {
    this.wt = new Thread()
    {
      public void run()
      {
        try
        {
          ProtoBuf localProtoBuf1 = new ProtoBuf(GmsProtos.REQUEST);
          localProtoBuf1.setLong(1, ActivityGmail.this.client_id);
          ProtoBuf localProtoBuf2 = localProtoBuf1.setNewProtoBuf(5);
          localProtoBuf2.setString(1, "label:" + ActivityGmail.this.label);
          localProtoBuf2.setLong(2, paramLong);
          localProtoBuf2.setInt(3, 22);
          localProtoBuf2.setInt(4, 5);
          final ProtoBuf localProtoBuf3 = GmsProtos.doRequest(ActivityGmail.this.credentials, localProtoBuf1).getProtoBuf(15);
          if (ActivityGmail.this.wt == this) {
            ActivityGmail.this.runOnUiThread(new Runnable()
            {
              public void run()
              {
                ActivityGmail.this.mList.removeFooterView(ActivityGmail.this.mLoading);
                ActivityGmail.this.data.add(localProtoBuf3);
                ActivityGmail.this.adapter.fireOnChanged();
                if (ActivityGmail.this.adapter.getCount() == 0)
                {
                  ActivityGmail.this.mList.setVisibility(8);
                  return;
                }
                ActivityGmail.this.mList.setVisibility(0);
              }
            });
          }
          ActivityGmail.access$1002(ActivityGmail.this, null);
          return;
        }
        catch (Exception localException)
        {
          for (;;)
          {
            localException.printStackTrace();
            App.reportThrowable(localException);
            if (ActivityGmail.this.wt == this) {
              ActivityGmail.this.runOnUiThread(new Runnable()
              {
                public void run()
                {
                  ActivityGmail.this.mLoading.setText("Error loading conversations");
                }
              });
            }
          }
        }
      }
    };
    this.wt.start();
  }
  
  private int loadLabels()
  {
    try
    {
      ProtoBuf localProtoBuf1 = new ProtoBuf(GmsProtos.REQUEST);
      localProtoBuf1.setLong(1, this.client_id);
      ProtoBuf localProtoBuf4 = localProtoBuf1.setNewProtoBuf(2);
      localProtoBuf4.setInt(1, 4);
      localProtoBuf4.addString(2, "^r");
      localProtoBuf4.addString(3, "^i");
      localProtoBuf4.addString(3, "^f");
      localProtoBuf4.addString(3, "^iim");
      GmsProtos.doRequest(this.credentials, localProtoBuf1);
      ProtoBuf localProtoBuf5 = new ProtoBuf(GmsProtos.REQUEST);
      localProtoBuf5.setLong(1, this.client_id);
      ProtoBuf localProtoBuf6 = localProtoBuf5.setNewProtoBuf(6);
      localProtoBuf6.setLong(1, 0L);
      localProtoBuf6.setLong(2, 0L);
      localProtoBuf6.setLong(3, 0L);
      localProtoBuf6.setLong(4, 0L);
      localProtoBuf6.setBool(5, true);
      localProtoBuf6.setBool(6, true);
      localProtoBuf6.setBool(7, true);
      ProtoBuf localProtoBuf7 = GmsProtos.doRequest(this.credentials, localProtoBuf5).getProtoBuf(4);
      localProtoBuf2 = localProtoBuf7;
    }
    catch (Exception localException1)
    {
      boolean bool2;
      do
      {
        for (;;)
        {
          int k;
          localException1.printStackTrace();
          App.reportThrowable(localException1);
          String str1 = localException1.getMessage();
          localProtoBuf2 = null;
          if (str1 != null)
          {
            int i = localException1.getMessage().indexOf("HTTP error 401");
            localProtoBuf2 = null;
            if (i >= 0)
            {
              boolean bool1 = this.ftoken;
              localProtoBuf2 = null;
              if (!bool1)
              {
                this.ftoken = true;
                if (!App.has_feature_gls) {
                  break label553;
                }
                Object localObject = getSystemService("account");
                if (localObject != null) {
                  try
                  {
                    Method[] arrayOfMethod = localObject.getClass().getMethods();
                    for (int m = 0;; m++)
                    {
                      int n = arrayOfMethod.length;
                      Method localMethod = null;
                      if (m < n)
                      {
                        if (("invalidateAuthToken".equals(arrayOfMethod[m].getName())) && (arrayOfMethod[m].getParameterTypes().length == 2)) {
                          localMethod = arrayOfMethod[m];
                        }
                      }
                      else
                      {
                        Object[] arrayOfObject = new Object[2];
                        arrayOfObject[0] = "com.google";
                        arrayOfObject[1] = this.credentials[1];
                        localMethod.invoke(localObject, arrayOfObject);
                        Thread local10 = new Thread()
                        {
                          public void run()
                          {
                            ActivityGmail.this.authorize(ActivityGmail.this.credentials[0]);
                          }
                        };
                        this.wt = local10;
                        this.wt.start();
                        return -1;
                      }
                    }
                  }
                  catch (Exception localException2)
                  {
                    localException2.printStackTrace();
                    App.reportThrowable(localException2);
                    localProtoBuf2 = null;
                  }
                }
              }
            }
          }
        }
        Intent localIntent = GoogleLoginServiceConstants.SERVICE_INTENT;
        ServiceConnection local11 = new ServiceConnection()
        {
          public void onServiceConnected(ComponentName paramAnonymousComponentName, IBinder paramAnonymousIBinder)
          {
            IGoogleLoginService localIGoogleLoginService = IGoogleLoginService.Stub.asInterface(paramAnonymousIBinder);
            try
            {
              localIGoogleLoginService.invalidateAuthToken(ActivityGmail.this.credentials[1]);
              ActivityGmail.this.unbindService(this);
              ActivityGmail.access$1002(ActivityGmail.this, new Thread()
              {
                public void run()
                {
                  ActivityGmail.this.authorize(ActivityGmail.this.credentials[0]);
                }
              });
              ActivityGmail.this.wt.start();
              return;
            }
            catch (Exception localException)
            {
              for (;;)
              {
                localException.printStackTrace();
                App.reportThrowable(localException);
              }
            }
          }
          
          public void onServiceDisconnected(ComponentName paramAnonymousComponentName) {}
        };
        bool2 = bindService(localIntent, local11, 1);
        ProtoBuf localProtoBuf2 = null;
      } while (!bool2);
      return -1;
      label553:
      SharedPreferences.Editor localEditor = this.prefs.edit();
      localEditor.putString("gmail_token_" + this.credentials[0], null);
      localEditor.commit();
      Thread local12 = new Thread()
      {
        public void run()
        {
          ActivityGmail.this.authorize(ActivityGmail.this.credentials[0]);
        }
      };
      this.wt = local12;
      this.wt.start();
      return -1;
    }
    if (localProtoBuf2 != null)
    {
      int j = localProtoBuf2.getCount(4);
      for (k = 0; k < j; k++)
      {
        ProtoBuf localProtoBuf3 = localProtoBuf2.getProtoBuf(4, k);
        long l = localProtoBuf3.getLong(1);
        String str2 = localProtoBuf3.getString(2);
        String str3 = localProtoBuf3.getString(3);
        if (!str2.startsWith("^"))
        {
          this.labels.add(str2);
          this.cn_labels.put(str2, str3);
        }
        this.id_labels.put(Long.valueOf(l), str2);
      }
      if (j > 0) {
        return 1;
      }
    }
    return 0;
  }
  
  private void showAccount(final String paramString)
  {
    showProgress(getResources().getString(2131099746));
    SharedPreferences.Editor localEditor = this.prefs.edit();
    localEditor.putString("gmail_account", paramString);
    localEditor.commit();
    this.labels.clear();
    this.labels.add("^i");
    this.labels.add("^t");
    this.labels.add("^b");
    this.labels.add("^f");
    this.labels.add("^r");
    this.labels.add("^all");
    this.labels.add("^s");
    this.labels.add("^k");
    Resources localResources = getResources();
    this.cn_labels.clear();
    this.cn_labels.put("^i", localResources.getString(2131099770));
    this.cn_labels.put("^t", localResources.getString(2131099771));
    this.cn_labels.put("^b", localResources.getString(2131099772));
    this.cn_labels.put("^f", localResources.getString(2131099773));
    this.cn_labels.put("^r", localResources.getString(2131099775));
    this.cn_labels.put("^all", localResources.getString(2131099776));
    this.cn_labels.put("^s", localResources.getString(2131099777));
    this.cn_labels.put("^k", localResources.getString(2131099778));
    this.id_labels.clear();
    this.wt = new Thread()
    {
      public void run()
      {
        ActivityGmail.this.authorize(paramString);
      }
    };
    this.wt.start();
  }
  
  private void showConversations(String paramString)
  {
    this.label = paramString;
    setTitle(getResources().getString(2131099700) + " - " + (String)this.cn_labels.get(paramString) + " - " + this.credentials[0]);
    this.mList.setVisibility(0);
    this.mLoading.setText(2131099757);
    if (this.mList.getFooterViewsCount() == 1) {
      this.mList.addFooterView(this.mLoading);
    }
    this.data.clear();
    this.adapter.fireOnChanged();
    loadConversations(9223372036854775807L);
  }
  
  private void xinit()
  {
    try
    {
      Thread.sleep(500L);
      label6:
      if (App.has_feature_gls)
      {
        Object localObject = getSystemService("account");
        if (localObject != null) {
          try
          {
            Object[] arrayOfObject = (Object[])localObject.getClass().getMethod("getAccountsByType", new Class[] { String.class }).invoke(localObject, new Object[] { "com.google" });
            this.al_objs = arrayOfObject;
            if (arrayOfObject != null)
            {
              this.al = new String[arrayOfObject.length];
              if (arrayOfObject.length > 0)
              {
                Field localField = arrayOfObject[0].getClass().getField("name");
                for (int j = 0; j < arrayOfObject.length; j++) {
                  this.al[j] = ((String)localField.get(arrayOfObject[j]));
                }
              }
            }
            return;
          }
          catch (Exception localException)
          {
            localException.printStackTrace();
            App.reportThrowable(localException);
            xinit_done();
          }
        }
        while (bindService(GoogleLoginServiceConstants.SERVICE_INTENT, new ServiceConnection()
        {
          public void onServiceConnected(ComponentName paramAnonymousComponentName, IBinder paramAnonymousIBinder)
          {
            IGoogleLoginService localIGoogleLoginService = IGoogleLoginService.Stub.asInterface(paramAnonymousIBinder);
            try
            {
              ActivityGmail.access$502(ActivityGmail.this, localIGoogleLoginService.getAccounts());
              ActivityGmail.this.xinit_done();
              ActivityGmail.this.unbindService(this);
              return;
            }
            catch (RemoteException localRemoteException)
            {
              for (;;)
              {
                localRemoteException.printStackTrace();
                App.reportThrowable(localRemoteException);
              }
            }
          }
          
          public void onServiceDisconnected(ComponentName paramAnonymousComponentName) {}
        }, 1)) {}
        xinit_done();
        return;
      }
      Vector localVector = new Vector();
      for (int i = 1;; i++)
      {
        String str = this.prefs.getString("gls_account_" + i, null);
        if (str == null) {
          break;
        }
        localVector.add(str);
      }
      this.al = ((String[])localVector.toArray(new String[0]));
      xinit_done();
      return;
    }
    catch (InterruptedException localInterruptedException)
    {
      break label6;
    }
  }
  
  private void xinit_done()
  {
    this.wt = null;
    runOnUiThread(new Runnable()
    {
      public void run()
      {
        String str1 = ActivityGmail.this.prefs.getString("gmail_account", null);
        String[] arrayOfString = ActivityGmail.this.al;
        String str2 = null;
        int j;
        if (arrayOfString != null)
        {
          int i = ActivityGmail.this.al.length;
          str2 = null;
          if (i > 0)
          {
            j = 0;
            int k = ActivityGmail.this.al.length;
            str2 = null;
            if (j < k)
            {
              if (!ActivityGmail.this.al[j].equals(str1)) {
                break label101;
              }
              str2 = str1;
            }
          }
        }
        if (str2 != null) {
          ActivityGmail.this.showAccount(str2);
        }
        label101:
        do
        {
          return;
          j++;
          break;
          ActivityGmail.this.hideProgress();
        } while (ActivityGmail.this.isFinishing());
        ActivityGmail.this.mList.showContextMenu();
      }
    });
  }
  
  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903053);
    setTitle(2131099700);
    this.client_id = System.currentTimeMillis();
    this.handler = new Handler();
    this.data = new Vector();
    this.labels = new Vector();
    this.id_labels = new Hashtable();
    this.cn_labels = new Hashtable();
    this.mList = ((ListView)findViewById(2131230725));
    this.mList.setOnCreateContextMenuListener(this);
    this.mLoading = new TextView(this);
    this.mLoading.setTextColor(-16777216);
    this.mLoading.setText(2131099757);
    int i = (int)(5.0F * getResources().getDisplayMetrics().density);
    this.mLoading.setPadding(i, i, i, i);
    this.mList.addFooterView(new View(this));
    this.mList.setFooterDividersEnabled(false);
    this.mList.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
      public void onItemClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
      {
        String[] arrayOfString = (String[])paramAnonymousView.getTag();
        if (arrayOfString != null)
        {
          Intent localIntent = new Intent();
          localIntent.putExtra("credentials", ActivityGmail.this.credentials[0] + "" + ActivityGmail.this.credentials[1]);
          localIntent.putExtra("client_id", ActivityGmail.this.client_id);
          localIntent.putExtra("conversation_id", arrayOfString[0]);
          localIntent.putExtra("messages_count", arrayOfString[1]);
          localIntent.putExtra("labels", arrayOfString[2]);
          Enumeration localEnumeration = ActivityGmail.this.id_labels.keys();
          while (localEnumeration.hasMoreElements())
          {
            Long localLong = (Long)localEnumeration.nextElement();
            String str = (String)ActivityGmail.this.id_labels.get(localLong);
            if ("^t".equals(str)) {
              localIntent.putExtra("s_label_id", localLong);
            } else if ("^u".equals(str)) {
              localIntent.putExtra("u_label_id", localLong);
            }
          }
          localIntent.setClass(ActivityGmail.this, ActivityGmailConversation.class);
          ActivityGmail.this.startActivity(localIntent);
        }
      }
    });
    this.adapter = new MyAdapter();
    this.mList.setAdapter(this.adapter);
    this.mList.setVisibility(8);
    this.ftoken = false;
    showProgress(getResources().getString(2131099746));
  }
  
  public void onCreateContextMenu(ContextMenu paramContextMenu, View paramView, ContextMenu.ContextMenuInfo paramContextMenuInfo)
  {
    paramContextMenu.setHeaderTitle(getResources().getString(2131099664));
    if (this.al != null) {
      for (int i = 0; i < this.al.length; i++) {
        paramContextMenu.add(0, i + 1000, 0, this.al[i]);
      }
    }
    if ((!App.has_feature_gls) || (getSystemService("account") != null)) {
      paramContextMenu.add(0, 999, 0, 2131099665);
    }
  }
  
  public boolean onCreateOptionsMenu(Menu paramMenu)
  {
    return true;
  }
  
  public boolean onMenuItemSelected(int paramInt, MenuItem paramMenuItem)
  {
    int i = paramMenuItem.getItemId();
    if (i == 999)
    {
      if (App.has_feature_gls)
      {
        final Object localObject = getSystemService("account");
        if (localObject != null)
        {
          this.wt = new Thread()
          {
            public void run()
            {
              try
              {
                Method[] arrayOfMethod = localObject.getClass().getMethods();
                for (int i = 0;; i++)
                {
                  int j = arrayOfMethod.length;
                  Method localMethod = null;
                  if (i < j)
                  {
                    if ("addAccount".equals(arrayOfMethod[i].getName())) {
                      localMethod = arrayOfMethod[i];
                    }
                  }
                  else
                  {
                    Object localObject1 = localObject;
                    Object[] arrayOfObject = new Object[7];
                    arrayOfObject[0] = "com.google";
                    arrayOfObject[1] = null;
                    arrayOfObject[2] = null;
                    arrayOfObject[3] = null;
                    arrayOfObject[4] = ActivityGmail.this;
                    arrayOfObject[5] = null;
                    arrayOfObject[6] = null;
                    Object localObject2 = localMethod.invoke(localObject1, arrayOfObject);
                    String str = ((Bundle)localObject2.getClass().getMethod("getResult", new Class[0]).invoke(localObject2, new Object[0])).getString("authAccount");
                    if (str != null)
                    {
                      SharedPreferences.Editor localEditor = ActivityGmail.this.prefs.edit();
                      localEditor.putString("gmail_account", str);
                      localEditor.commit();
                      ActivityGmail.this.xinit();
                    }
                    return;
                  }
                }
                return;
              }
              catch (Exception localException)
              {
                localException.printStackTrace();
                App.reportThrowable(localException);
              }
            }
          };
          this.wt.start();
        }
      }
      for (;;)
      {
        return true;
        showAccount(null);
      }
    }
    if (i >= 1000)
    {
      showAccount(this.al[(i - 1000)]);
      return true;
    }
    if (i >= 10)
    {
      showConversations((String)this.labels.get(i - 10));
      return true;
    }
    return false;
  }
  
  public boolean onPrepareOptionsMenu(Menu paramMenu)
  {
    paramMenu.removeGroup(1);
    paramMenu.removeItem(1);
    SubMenu localSubMenu1 = paramMenu.addSubMenu(0, 1, 0, 2131099663);
    for (int i = 0; i < this.labels.size(); i++) {
      localSubMenu1.add(0, i + 10, 0, (CharSequence)this.cn_labels.get(this.labels.get(i)));
    }
    paramMenu.removeGroup(2);
    paramMenu.removeItem(2);
    SubMenu localSubMenu2 = paramMenu.addSubMenu(0, 2, 0, 2131099664);
    if (this.al != null) {
      for (int j = 0; j < this.al.length; j++) {
        localSubMenu2.add(0, j + 1000, 0, this.al[j]);
      }
    }
    if ((!App.has_feature_gls) || (getSystemService("account") != null)) {
      localSubMenu2.add(0, 999, 0, 2131099665);
    }
    return true;
  }
  
  protected void onResume()
  {
    super.onResume();
    if ((this.al == null) || (requesting_credentials != 0))
    {
      showProgress(getResources().getString(2131099746));
      this.wt = new Thread()
      {
        public void run()
        {
          ActivityGmail.this.xinit();
        }
      };
      this.wt.start();
    }
  }
  
  class MyAdapter
    implements ListAdapter
  {
    private List<DataSetObserver> observers = null;
    
    MyAdapter() {}
    
    public boolean areAllItemsEnabled()
    {
      return true;
    }
    
    public void fireOnChanged()
    {
      if (this.observers != null)
      {
        int i = this.observers.size();
        for (int j = 0; j < i; j++) {
          ((DataSetObserver)this.observers.get(j)).onChanged();
        }
      }
    }
    
    public int getCount()
    {
      int i = 0;
      for (int j = 0; j < ActivityGmail.this.data.size(); j++) {
        i += ((ProtoBuf)ActivityGmail.this.data.get(j)).getCount(3);
      }
      return i;
    }
    
    public Object getItem(int paramInt)
    {
      int i = 0;
      for (int j = 0; j < ActivityGmail.this.data.size(); j++)
      {
        ProtoBuf localProtoBuf = (ProtoBuf)ActivityGmail.this.data.get(j);
        int k = localProtoBuf.getCount(3);
        if (paramInt < i + k) {
          return localProtoBuf.getProtoBuf(3, paramInt - i);
        }
        i += k;
      }
      return null;
    }
    
    public long getItemId(int paramInt)
    {
      return ((ProtoBuf)getItem(paramInt)).getLong(1);
    }
    
    public int getItemViewType(int paramInt)
    {
      return 0;
    }
    
    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
      if (paramInt == -1 + getCount())
      {
        long l2 = ((ProtoBuf)ActivityGmail.this.data.lastElement()).getLong(2);
        if ((l2 != 0L) && (ActivityGmail.this.wt == null))
        {
          ActivityGmail.this.mLoading.setText(2131099757);
          if (ActivityGmail.this.mList.getFooterViewsCount() == 1) {
            ActivityGmail.this.mList.addFooterView(ActivityGmail.this.mLoading);
          }
          ActivityGmail.this.loadConversations(l2);
        }
      }
      if (paramView == null) {
        paramView = ActivityGmail.this.getLayoutInflater().inflate(2130903055, paramViewGroup, false);
      }
      ProtoBuf localProtoBuf1 = (ProtoBuf)getItem(paramInt);
      HashSet localHashSet = new HashSet();
      int i = localProtoBuf1.getCount(11);
      for (int j = 0; j < i; j++)
      {
        String str8 = (String)ActivityGmail.this.id_labels.get(Long.valueOf(localProtoBuf1.getLong(11, j)));
        if (str8 != null) {
          localHashSet.add(str8);
        }
      }
      ImageView localImageView = (ImageView)paramView.findViewById(2131230770);
      StringBuilder localStringBuilder1 = new StringBuilder();
      StringBuffer localStringBuffer = new StringBuffer();
      int k = 0;
      int m = 0;
      Iterator localIterator = localHashSet.iterator();
      while (localIterator.hasNext())
      {
        String str6 = (String)localIterator.next();
        if ("^t".equals(str6)) {
          k = 1;
        }
        if ("^u".equals(str6)) {
          m = 1;
        }
        String str7 = (String)ActivityGmail.this.cn_labels.get(str6);
        if ((str7 != null) && (!ActivityGmail.this.label.equals(str6)) && ((!str6.startsWith("^")) || ("^i".equals(str6))))
        {
          if (localStringBuffer.length() > 0) {
            localStringBuffer.append(", ");
          }
          localStringBuffer.append(str7);
        }
        if (str7 != null)
        {
          localStringBuilder1.append(str7);
          localStringBuilder1.append('\000');
        }
      }
      String[] arrayOfString = new String[3];
      arrayOfString[0] = String.valueOf(localProtoBuf1.getLong(1));
      arrayOfString[1] = String.valueOf(localProtoBuf1.getInt(8));
      arrayOfString[2] = localStringBuilder1.toString();
      paramView.setTag(arrayOfString);
      if (k != 0) {
        localImageView.setImageResource(2130837572);
      }
      for (;;)
      {
        TextView localTextView1 = (TextView)paramView.findViewById(2131230773);
        localTextView1.setText(localStringBuffer);
        int n;
        label484:
        TextView localTextView2;
        String str3;
        String str4;
        ProtoBuf localProtoBuf2;
        SpannableStringBuilder localSpannableStringBuilder;
        if (localStringBuffer.length() > 0)
        {
          n = 0;
          localTextView1.setVisibility(n);
          localTextView2 = (TextView)paramView.findViewById(2131230771);
          String str1 = localProtoBuf1.getString(4);
          String str2 = localProtoBuf1.getString(5);
          StringBuilder localStringBuilder2 = new StringBuilder().append(str1);
          if ((str1.length() <= 0) || (str2.length() <= 0)) {
            break label814;
          }
          str3 = " - ";
          localTextView2.setText(str3 + str2);
          str4 = "";
          int i1 = localProtoBuf1.getInt(6);
          if (i1 == 2) {
            str4 = "» ";
          }
          if (i1 == 1) {
            str4 = "› ";
          }
          localProtoBuf2 = localProtoBuf1.getProtoBuf(10);
          localSpannableStringBuilder = new SpannableStringBuilder();
        }
        try
        {
          ActivityGmail.getSenderSnippet(localProtoBuf2, localSpannableStringBuilder, 64, new StyleSpan(1), new ForegroundColorSpan(-65536), "Me", "Draft", "Drafts", false, false);
          localSpannableStringBuilder.insert(0, str4);
          ((TextView)paramView.findViewById(2131230727)).setText(localSpannableStringBuilder);
          if (m != 0)
          {
            localTextView2.setTypeface(Typeface.DEFAULT_BOLD, 1);
            long l1 = localProtoBuf1.getLong(3);
            localDate1 = new Date(l1);
            localDate2 = new Date();
            if (localDate2.getYear() == localDate1.getYear()) {
              break label848;
            }
            str5 = ActivityGmail.df3.format(localDate1);
            ((TextView)paramView.findViewById(2131230774)).setText(str5);
            View localView = paramView.findViewById(2131230772);
            if (!localProtoBuf1.getBool(9)) {
              break label900;
            }
            i2 = 0;
            localView.setVisibility(i2);
            return paramView;
            localImageView.setImageResource(2130837571);
            continue;
            n = 8;
            break label484;
            label814:
            str3 = "";
          }
        }
        catch (Exception localException)
        {
          label900:
          for (;;)
          {
            Date localDate1;
            Date localDate2;
            String str5;
            int i2;
            localException.printStackTrace();
            App.reportThrowable(localException);
            continue;
            localTextView2.setTypeface(Typeface.DEFAULT, 0);
            continue;
            label848:
            if ((localDate2.getMonth() != localDate1.getMonth()) || (localDate2.getDate() != localDate1.getDate()))
            {
              str5 = ActivityGmail.df2.format(localDate1);
            }
            else
            {
              str5 = ActivityGmail.df1.format(localDate1);
              continue;
              i2 = 8;
            }
          }
        }
      }
    }
    
    public int getViewTypeCount()
    {
      return 1;
    }
    
    public boolean hasStableIds()
    {
      return true;
    }
    
    public boolean isEmpty()
    {
      return getCount() == 0;
    }
    
    public boolean isEnabled(int paramInt)
    {
      return true;
    }
    
    public void registerDataSetObserver(DataSetObserver paramDataSetObserver)
    {
      if (this.observers == null) {
        this.observers = new ArrayList();
      }
      if (!this.observers.contains(paramDataSetObserver)) {
        this.observers.add(paramDataSetObserver);
      }
    }
    
    public void unregisterDataSetObserver(DataSetObserver paramDataSetObserver)
    {
      if (this.observers == null) {
        return;
      }
      this.observers.remove(paramDataSetObserver);
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.ActivityGmail
 * JD-Core Version:    0.7.0.1
 */